package com.sangeng.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sangeng.domain.entity.user.UserRole;
import com.sangeng.mapper.UserRoleMapper;
import com.sangeng.service.IUserRoleService;
import org.springframework.stereotype.Service;

@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {
    /**
     * 根据用户id查询角色id
     */
    @Override
    public void add(Long id, Long roleId) {
        UserRole userRole = new UserRole(id, roleId);
        save(userRole);
    }

    /**
     * 根据用户id查询角色id
     */
    @Override
    public Long getRoleIdByUserId(Long userId) {
        UserRole userRole = lambdaQuery().eq(UserRole::getUserId, userId).one();
        return userRole.getRoleId();
    }
}
